package com.wb3.meta.api.core.controller;

import com.wb3.meta.api.core.service.UserChatListService;
import com.wb3.meta.api.core.vo.ReqUserChatListVo;
import com.wb3.meta.common.annotation.NoPermission;
import com.wb3.meta.common.annotation.RequireAuth;
import com.wb3.meta.common.authentication.RequestHolder;
import com.wb3.meta.common.plugin.BaseResultController;
import com.wb3.meta.common.pojo.ResultT;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户聊天相关接口")
@RequestMapping("base/user/chat")
public class UserChatListController extends BaseResultController<ReqUserChatListVo> {

    @Autowired
    private UserChatListService userChatListService;

    /**
     * 列表接口
     *
     * @param reqUserChatListVo fd
     */
    @RequireAuth
    @Override
    @ApiOperation("聊天列表接口")
    @GetMapping("list")
    public ResultT list(ReqUserChatListVo reqUserChatListVo) {
        reqUserChatListVo.setUserId(RequestHolder.getUserId());
        return userChatListService.getModelMapPage(reqUserChatListVo);
    }


    /**
     * 明细接口
     *
     * @param reqUserChatListVo
     */
    @RequireAuth
    @Override
    @ApiOperation("详情接口")
    @GetMapping("detail")
    public ResultT detail(ReqUserChatListVo reqUserChatListVo) {
        return userChatListService.getModelMapById(reqUserChatListVo.getId());
    }

    /**
     * 新增or更新接口
     *
     * @param reqUserChatListVo
     */
    @RequireAuth
    @Override
    @ApiOperation("更新接口")
    @PostMapping("update")
    public ResultT saveOrUpdate(@RequestBody ReqUserChatListVo reqUserChatListVo) {
        return userChatListService.saveOrUpdate(reqUserChatListVo);
    }

    /**
     * 删除接口
     *
     * @param reqUserChatListVo
     */
    @NoPermission
    @Override
    @ApiOperation("删除接口")
    @PostMapping("delete")
    public ResultT delete(@RequestBody ReqUserChatListVo reqUserChatListVo) {
        return userChatListService.delete(reqUserChatListVo);
    }

    @RequireAuth
    @ApiOperation("创建一个会话")
    @PostMapping("create")
    public ResultT createChat(@RequestBody ReqUserChatListVo reqUserChatListVo) {
        return userChatListService.createChat(reqUserChatListVo);
    }
}
